import pytest

from utilities.webdriver_factory import *
from utilities.config_reader import *

from pages.login_page import LoginPage

@pytest.fixture(scope="session")
def config():
    return ConfigReader()

@pytest.fixture(scope="session")
def driver(config):
    driver = WebDriverFactory.get_driver(
        browser_type=config.config.get("browser", ""),
        headless=config.config.get("headless"),
        implicit_wait_time=config.config.get("implicit_wait_time", 30)
    )
    yield driver
    driver.quit()

@pytest.fixture(scope="session")
def login_page(driver, config):
    bmc_config = config.get_bmc_config("sku1")
    login_page = LoginPage(driver)
    login_page.open_login_page(bmc_config["bmc_ip"])
    login_page.enter_username(bmc_config["bmc_username"])
    login_page.enter_password(bmc_config["bmc_password"])
    login_page.click_login()

    """处理弹窗"""
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    WebDriverWait(driver, 10).until(EC.alert_is_present())
    alert = driver.switch_to.alert
    alert.accept()
    return login_page

@pytest.fixture
def assert_info_page(driver):
    from pages.navigation_page import NavigationPage
    navigation = NavigationPage(driver)
    navigation.navigation_to_system_info()
    navigation.navigation_to_asset_info()

    from pages.asset_info_page import AssetInfoPage
    return AssetInfoPage(driver)

@pytest.fixture
def hw_moniter_page(driver):
    from pages.navigation_page import NavigationPage
    navigation = NavigationPage(driver)
    navigation.navigation_to_system_info()
    navigation.navigation_to_hw_moniter()

    from pages.HW_moniter_page import HWMoniterPage
    return HWMoniterPage(driver)




